//package org.convallaria.system.biz.controller.other;
//
//import io.swagger.v3.oas.annotations.Operation;
//import io.swagger.v3.oas.annotations.Parameter;
//import io.swagger.v3.oas.annotations.tags.Tag;
//import lombok.RequiredArgsConstructor;
//import lombok.extern.slf4j.Slf4j;
//import org.convallaria.framework.common.result.ApiResult;
//import org.convallaria.framework.security.annotation.RequiresPermissions;
//import org.convallaria.framework.security.annotation.RequiresRoles;
//import org.convallaria.framework.security.config.SecurityProperties;
//import org.convallaria.framework.security.service.TokenService;
//import org.convallaria.framework.security.util.SecurityUtils;
//import org.convallaria.system.biz.service.SecurityConfigService;
//import org.convallaria.system.biz.service.TokenBlacklistService;
//import org.convallaria.system.biz.service.auth.AuthService;
//import org.springframework.web.bind.annotation.DeleteMapping;
//import org.springframework.web.bind.annotation.GetMapping;
//import org.springframework.web.bind.annotation.PostMapping;
//import org.springframework.web.bind.annotation.RequestBody;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.RequestParam;
//import org.springframework.web.bind.annotation.RestController;
//
//import java.util.HashMap;
//import java.util.Map;
//
///**
// * @Description <p>描述： </p>
// * @Author gjh
// * @Date 2025/9/27 17:27
// */
//@Slf4j
//@RestController
//@RequestMapping("/other")
//@RequiredArgsConstructor
//@Tag(name = "其他", description = "其他、验证和管理API")
//public class OtherController {
//
//    private final AuthService authService;
//    private final SecurityConfigService securityConfigService;
//    private final TokenBlacklistService tokenBlacklistService;
//    private final TokenService tokenService;
//    private final SecurityProperties securityProperties;
//
//    @Operation(summary = "测试权限 - 需要ADMIN角色")
//    @GetMapping("/test/admin")
//    @RequiresRoles("ADMIN")
//    public ApiResult<String> testAdminRole() {
//        return ApiResult.success("Hello Admin! Current user: " + SecurityUtils.getCurrentUsername());
//    }
//
//    @Operation(summary = "测试权限 - 需要user:view权限")
//    @GetMapping("/test/permission")
//    @RequiresPermissions("user:view")
//    public ApiResult<String> testPermission() {
//        return ApiResult.success("You have user:view permission! Current user: " + SecurityUtils.getCurrentUsername());
//    }
//
//    @Operation(summary = "测试权限 - 需要ADMIN或USER角色")
//    @GetMapping("/test/roles")
//    @RequiresRoles(value = {"ADMIN", "USER"}, logical = RequiresRoles.Logical.OR)
//    public ApiResult<String> testMultipleRoles() {
//        return ApiResult.success("You have ADMIN or USER role! Current user: " + SecurityUtils.getCurrentUsername());
//    }
//
//    @RequiresPermissions("system:security:config")
//    @Operation(summary = "获取安全配置")
//    @GetMapping("/security-config")
//    public ApiResult<SecurityConfigService.SecurityConfig> getSecurityConfig() {
//        return ApiResult.success(securityConfigService.getSecurityConfig());
//    }
//
//    @RequiresPermissions("system:security:config")
//    @Operation(summary = "更新安全配置")
//    @PostMapping("/security-config")
//    public ApiResult<Void> updateSecurityConfig(@RequestBody SecurityConfigService.SecurityConfig config) {
//        securityConfigService.updateSecurityConfig(config);
//        return ApiResult.success();
//    }
//
//    @RequiresPermissions("system:security:config")
//    @Operation(summary = "获取密码策略配置")
//    @GetMapping("/password-policy")
//    public ApiResult<SecurityConfigService.PasswordPolicyConfig> getPasswordPolicyConfig() {
//        return ApiResult.success(securityConfigService.getPasswordPolicyConfig());
//    }
//
//    @RequiresPermissions("system:security:config")
//    @Operation(summary = "更新密码策略配置")
//    @PostMapping("/password-policy")
//    public ApiResult<Void> updatePasswordPolicyConfig(@RequestBody SecurityConfigService.PasswordPolicyConfig config) {
//        securityConfigService.updatePasswordPolicyConfig(config);
//        return ApiResult.success();
//    }
//
//    @RequiresPermissions("system:security:config")
//    @Operation(summary = "获取黑名单统计信息", description = "获取黑名单的统计信息")
//    @GetMapping("/blacklist/statistics")
//    public ApiResult<TokenBlacklistService.BlacklistStatistics> getBlacklistStatistics() {
//        try {
//            TokenBlacklistService.BlacklistStatistics statistics = tokenBlacklistService.getStatistics();
//            return ApiResult.success(statistics);
//        } catch (Exception e) {
//            return ApiResult.error("获取黑名单统计信息失败: " + e.getMessage());
//        }
//    }
//
//    @RequiresPermissions("system:security:config")
//    @Operation(summary = "清理过期黑名单Token", description = "清理过期的黑名单Token")
//    @PostMapping("/blacklist/clean")
//    public ApiResult<Map<String, Object>> cleanExpiredBlacklistTokens() {
//        try {
//            tokenBlacklistService.cleanExpiredTokens();
//            Map<String, Object> result = new HashMap<>();
//            result.put("success", true);
//            result.put("message", "清理过期黑名单Token完成");
//            return ApiResult.success(result);
//        } catch (Exception e) {
//            return ApiResult.error("清理过期黑名单Token失败: " + e.getMessage());
//        }
//    }
//
//    @Operation(summary = "获取Token统计信息", description = "获取Token的统计信息")
//    @GetMapping("/token/statistics")
//    public ApiResult<TokenService.TokenStatistics> getTokenStatistics() {
//        try {
//            TokenService.TokenStatistics statistics = tokenService.getTokenStatistics();
//            return ApiResult.success(statistics);
//        } catch (Exception e) {
//            return ApiResult.error("获取Token统计信息失败: " + e.getMessage());
//        }
//    }
//
//    // ==================== 黑名单管理相关接口 ====================
//
//    @RequiresPermissions("system:security:config")
//    @Operation(summary = "将Token加入黑名单", description = "将Token加入黑名单")
//    @PostMapping("/blacklist")
//    public ApiResult<Map<String, Object>> addToBlacklist(
//            @Parameter(description = "JWT Token", example = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...")
//            @RequestParam String token,
//            @Parameter(description = "加入黑名单的原因", example = "用户主动登出")
//            @RequestParam String reason) {
//
//        try {
//            tokenBlacklistService.addToBlacklist(token, reason);
//            Map<String, Object> result = new HashMap<>();
//            result.put("success", true);
//            result.put("message", "Token已加入黑名单");
//            result.put("token", token);
//            result.put("reason", reason);
//            return ApiResult.success(result);
//        } catch (Exception e) {
//            return ApiResult.error("添加Token到黑名单失败: " + e.getMessage());
//        }
//    }
//
//    @RequiresPermissions("system:security:config")
//    @Operation(summary = "检查Token是否在黑名单中", description = "检查Token是否在黑名单中")
//    @GetMapping("/blacklist/check")
//    public ApiResult<Map<String, Object>> checkBlacklist(
//            @Parameter(description = "JWT Token", example = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...")
//            @RequestParam String token) {
//
//        boolean isBlacklisted = tokenBlacklistService.isBlacklisted(token);
//        Map<String, Object> result = new HashMap<>();
//        result.put("token", token);
//        result.put("isBlacklisted", isBlacklisted);
//        result.put("message", isBlacklisted ? "Token在黑名单中" : "Token不在黑名单中");
//        return ApiResult.success(result);
//    }
//
//    @RequiresPermissions("system:security:config")
//    @Operation(summary = "从黑名单中移除Token", description = "从黑名单中移除Token")
//    @DeleteMapping("/blacklist")
//    public ApiResult<Map<String, Object>> removeFromBlacklist(
//            @Parameter(description = "JWT Token", example = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...")
//            @RequestParam String token) {
//
//        try {
//            tokenBlacklistService.removeFromBlacklist(token);
//            Map<String, Object> result = new HashMap<>();
//            result.put("success", true);
//            result.put("message", "Token已从黑名单中移除");
//            result.put("token", token);
//            return ApiResult.success(result);
//        } catch (Exception e) {
//            return ApiResult.error("从黑名单中移除Token失败: " + e.getMessage());
//        }
//    }
//}
